auto.waitFor();
var myFunc = require("./myCommonFunction.js");


var now = new Date();
var date = now.getDate();
var month = now.getMonth();


// var startTime = now.getTime();
threads.start(function () {
    sleep(1200000)
    storages.remove(month + '-' + (date - 1));
    exit();
});
// var b = device.getMusicVolume();
// device.setMusicVolume(0);
opreate();
// device.setMusicVolume(b);

// storages.remove(month + '-' + (date - 1));

function opreate(){
    try {
        myFunc.openMyApp('京喜特价')
        var a = myFunc.findOne('搜索', 5000);
        click(546, 2340);
        a =  myFunc.findOne('第一周', 5000);
        if(a == null) {
            reOpreate()
            return;
        }
        idContains('cc').findOnce().click();
        sleep(1000);
        var task  = myFunc.find('去赚钱');
        for (let index = 0; index < task.length; index++) {
            let element = task[index];
            myFunc.clickCenter(element);
            while(myFunc.findOne('今日已完成', 1000) == null){
                myFunc.clickByText("点击逛下一个");
                sleep(5000)
                if(!scrollDown()){
                    swipe(500, 2000, 500, 1000, 500)
                }
                sleep(1000)
                if(!scrollDown()){
                    swipe(500, 2000, 500, 1000, 500)
                }
                sleep(1000)
                if(!scrollDown()){
                    swipe(500, 2000, 500, 1000, 500)
                }
                sleep(1000)
            }
            myFunc.tuichuToStr('分亿万京豆抵钱花');
        }
        var taskWord = ['去赚钱','开小店','去逛逛', '瓜分京豆'];
        for (let index = 0; index < taskWord.length; index++) {
            myFunc.clickByText(taskWord[index]);
            sleep(3000);
            myFunc.tuichuToStr('分亿万京豆抵钱花');
        }
        sleep(1000);
        scrollDown();
        sleep(1000);
        var taskWord = ['去签到','去签到','去领取', '去参加', '养猪猪'];
        for (let index = 0; index < taskWord.length; index++) {
            myFunc.clickByText(taskWord[index]);
            sleep(3000);
            myFunc.tuichuToStr('分亿万京豆抵钱花');
        }
        myFunc.tuichuToStr('赚金币');
        for (let index = 0; index < 3; index++) {
            click(300, 450)
            sleep(100)
            click(450, 385)
            sleep(100)
            click(600, 385)
            sleep(100)
            click(750, 450)
            sleep(2000)
        }
        myFunc.tuichu('京喜特价')
    }catch(e) {
        log('error', e)
        reOpreate()
    }
}

function reOpreate(){
    myFunc.tuichu('京喜特价')
    opreate()
}
if(false) {
    
}